package cn.jingyuan.swan.uaa.helper;

import cn.jingyuan.bee.utils.ObjectUtils;
import cn.jingyuan.bee.utils.bean.BeanUtils;
import cn.jingyuan.swan.cloud.oauth2.DefaultAuthority;
import cn.jingyuan.swan.system.model.SimpleAuthority;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class SysAuthorityHelper {

    public static Collection<DefaultAuthority> to(Collection<SimpleAuthority> simpleAuthorities) {
        List<DefaultAuthority> defaultAuthorities = Collections.emptyList();
        if (ObjectUtils.isNotEmpty(defaultAuthorities)) {
            defaultAuthorities = new ArrayList<>(simpleAuthorities.size());
            for (SimpleAuthority authority : simpleAuthorities) {
                DefaultAuthority defaultAuthority = new DefaultAuthority();
                BeanUtils.copyProperties(authority, defaultAuthority);

                defaultAuthorities.add(defaultAuthority);
            }
        }
        return defaultAuthorities;
    }

}
